﻿<UserControl x:Class="ModernAudioTagger.Content.ContentRename"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:vm="clr-namespace:ModernAudioTagger.ViewModel"
             xmlns:content="clr-namespace:ModernAudioTagger.Content"
             xmlns:provider="clr-namespace:ModernAudioTagger.Provider"
             xmlns:converter="clr-namespace:ModernAudioTagger.Converter"
             xmlns:helper="clr-namespace:ModernAudioTagger.Helpers"
             xmlns:view="clr-namespace:ModernAudioTagger.View"
             xmlns:mscorlib="clr-namespace:System;assembly=mscorlib"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">

    <UserControl.DataContext>
        <Binding Source="{x:Static provider:ViewModelLocator.Instance}" Path="RenameVM" />
    </UserControl.DataContext>


    <UserControl.Resources>
        <mscorlib:Double x:Key="textbox_height">20</mscorlib:Double>
        <mscorlib:Double x:Key="text_width">200</mscorlib:Double>
        <converter:FilenameConverter x:Key="filenameConverter" />
        <converter:NullToVisibilityConverter x:Key="nullToVisibilityConverter" />
        <converter:ArraySplitConverter x:Key="arraysplitConverter" />
        <converter:IsEqualOrGreaterThanConverter x:Key="isEqualOrGreaterThanConverter" />
        <ObjectDataProvider x:Key="renameTarget" 
                        MethodName="GetValues" ObjectType="{x:Type mscorlib:Enum}">
            <ObjectDataProvider.MethodParameters>
                <helper:Type2Extension TypeName="vm:RenameViewModel+RENAME_TARGET" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </UserControl.Resources>

    <DockPanel>
        <StackPanel DockPanel.Dock="Top">            
            <Grid
                Margin="{StaticResource DefaultTopMargin}"                 
                >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="70*"></ColumnDefinition>
                    <ColumnDefinition Width="30*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <TextBlock Text="INPUT" Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopMargin}" />
                <TextBox                 
                    Grid.Row="1"
                    Text="{Binding InputPattern, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                                       
                    >                    
                </TextBox>
                <TextBlock Grid.Column="1" Text="TARGET" Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopMargin}" />
                <ComboBox Grid.Column="1" Grid.Row="1"                          
                    Margin="{StaticResource DefaultLeftMargin}" 
                    ItemsSource="{Binding Source={StaticResource renameTarget}}"
                    SelectedValue="{Binding SelectedTarget, Mode=TwoWay}"
                    SelectedIndex="0"                          
                    >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction Command="{Binding UpdatePatternsCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </ComboBox>
            </Grid>

            <TextBlock Text="PREVIEW" Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopMargin}" />
            <TextBox IsReadOnly="True" Text="{Binding Preview, Mode=OneWay}"  Margin="{StaticResource DefaultTopMargin}" />

        </StackPanel>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50*"></ColumnDefinition>
                <ColumnDefinition Width="50*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>

            <DockPanel>

                <StackPanel DockPanel.Dock="Top">

                    <StackPanel Orientation="Horizontal" Margin="{StaticResource DefaultTopMargin}">
                        <TextBlock Text="LEGENDA / COMMON PATTERNS" Style="{StaticResource Heading2}" />

                        <mui:ModernButton IconData="{StaticResource arrowUpPathData}" Margin="{StaticResource DefaultLeftMargin}" >
                            <mui:ModernButton.CommandParameter>
                                <mscorlib:Boolean>False</mscorlib:Boolean>
                            </mui:ModernButton.CommandParameter>
                            <mui:ModernButton.Command>
                                <Binding Path="AddToInputCommand" />
                            </mui:ModernButton.Command>
                        </mui:ModernButton>                        
                    </StackPanel>

                </StackPanel>

                <ListBox SelectionMode="Single" 
                         BorderThickness="1" 
                         BorderBrush="{DynamicResource SeparatorBackground}" 
                         x:Name="cbPatterns" 
                         VerticalAlignment="Top" 
                         DisplayMemberPath="Value" 
                         SelectedValuePath="Key" 
                         SelectedValue="{Binding SelectedPattern, Mode=TwoWay}"
                         ItemsSource="{Binding Patterns, Mode=OneWay}" 
                         Margin="0, 8, 0, 0" 
                         DockPanel.Dock="Bottom" 
                         >
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseDoubleClick">
                            <i:InvokeCommandAction Command="{Binding AddToInputCommand}" >
                                <i:InvokeCommandAction.CommandParameter>
                                    <mscorlib:Boolean>True</mscorlib:Boolean>
                                </i:InvokeCommandAction.CommandParameter>
                            </i:InvokeCommandAction>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </ListBox>


            </DockPanel>

            <ScrollViewer 
                Margin="0, 8, 0, 0"
                Grid.Row="1">

                <Border            
                    BorderThickness="1"
                    BorderBrush="{DynamicResource SeparatorBackground}"
                >

                    <StackPanel IsEnabled="False">
                        <!--<DockPanel >-->
                        <Grid >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>

                            <TextBlock
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}"
                            HorizontalAlignment="Left"
                            Width="Auto"
                            Grid.Row="0"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Text="Title" Style="{StaticResource Heading2}" />
                            <TextBox                            
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            HorizontalAlignment="Left"
                            Width="{StaticResource text_width}"                  
                            Text="{Binding SelectedModelTag.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                            Grid.Row="0" Grid.Column="1" 
                        />

                            <!-- Position -->
                            <TextBlock 
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Width="Auto"
                            HorizontalAlignment="Left"
                            Grid.Row="1"                    
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Text="Position" Style="{StaticResource Heading2}" />
                            <TextBox 
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            HorizontalAlignment="Left"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Width="30"                  
                            Text="{Binding SelectedModelTag.Position, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                            Grid.Row="1" Grid.Column="1" 
                        />
                            <!-- Track Artists -->
                            <TextBlock                     
                            Grid.Row="2"
                            FontSize="{StaticResource SmallFontSize}" 
                            Height="{StaticResource textbox_height}"
                            Width="Auto"
                            HorizontalAlignment="Left"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Text="Track Artists" Style="{StaticResource Heading2}" />
                            <TextBox   
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Text="{Binding SelectedModelTag.TrackArtists, Converter={StaticResource arraysplitConverter}, Mode=TwoWay}" 
                            Grid.Column="1" Grid.Row="2"               
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Width="{StaticResource text_width}"             
                            HorizontalAlignment="Left"
                            >
                            </TextBox>

                            <!-- Album -->
                            <TextBlock 
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Width="Auto"
                            HorizontalAlignment="Left"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Text="Album" Style="{StaticResource Heading2}" 
                            Grid.Row="3"
                         />
                            <TextBox    
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Text="{Binding SelectedModelTag.Album, Mode=TwoWay}" 
                            Grid.Column="1" Grid.Row="3"               
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Width="{StaticResource text_width}"        
                            HorizontalAlignment="Left"
                            >
                            </TextBox>

                            <!-- Album Artists -->
                            <TextBlock 
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Width="Auto"
                            HorizontalAlignment="Left"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Text="Album Artists" Style="{StaticResource Heading2}" 
                            Grid.Row="4"
                        />
                            <TextBox       
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Text="{Binding SelectedModelTag.AlbumArtists, Converter={StaticResource arraysplitConverter}, Mode=TwoWay}" 
                            Grid.Column="1" Grid.Row="4"               
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Width="{StaticResource text_width}"        
                            HorizontalAlignment="Left"
                            >
                            </TextBox>
                            <TextBlock 
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            Width="Auto"
                            HorizontalAlignment="Left"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Text="Year" Style="{StaticResource Heading2}" 
                            Grid.Row="5"
                        />
                            <TextBox 
                            Height="{StaticResource textbox_height}"
                            FontSize="{StaticResource SmallFontSize}" 
                            HorizontalAlignment="Left"
                            Margin="{StaticResource DefaultTopLeftMargin}" 
                            Width="{StaticResource text_width}"    
                            Text="{Binding SelectedModelTag.Year, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                            Grid.Row="5" Grid.Column="1" />
                        </Grid>
                    </StackPanel>

                    <!--</DockPanel>-->
                </Border>
            </ScrollViewer>

            <content:ContentFileListRename Grid.Column="1" Grid.RowSpan="2" Margin="{StaticResource DefaultTopMargin}" />

            <!--<DockPanel Grid.Column="1" Grid.RowSpan="2" Margin="{StaticResource DefaultTopMargin}">

                <DockPanel.Style>
                    <Style TargetType="{x:Type DockPanel}">
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Files.Count, Converter={StaticResource isEqualOrGreaterThanConverter}, ConverterParameter='1'}" Value="True">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DockPanel.Style>

                <Expander Header="Expand for more options"
                          DockPanel.Dock="Top">
                    <StackPanel>
                        <TextBlock FontSize="{StaticResource SmallFontSize}" Text="Path" Style="{StaticResource Title}" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}" />

                        <TextBlock             
                                Visibility="{Binding SelectedPath, Converter={StaticResource nullToVisibilityConverter}, ConverterParameter=False}"
                                Height="Auto" 
                                Width="Auto"             
                                FontSize="{StaticResource SmallFontSize}" 
                                HorizontalAlignment="Center" 
                                Margin="{StaticResource DefaultTopMargin}">     
                                <Hyperlink Command="{x:Static view:ViewCommands.OpenFolderLocation}" CommandParameter="{Binding SelectedPath}" >
                                    <TextBlock Text="{Binding SelectedPath}"></TextBlock>
                                </Hyperlink>
                            </TextBlock>
                        <TextBlock Height="Auto" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center" Width="Auto" Margin="{StaticResource DefaultTopMargin}"  Visibility="{Binding SelectedPath, Converter={StaticResource nullToVisibilityConverter}}">
                                <Hyperlink Command="{Binding OpenFolderDialogCommand}">Click here</Hyperlink>
                        </TextBlock>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}">
                            <TextBlock VerticalAlignment="Center" FontSize="{StaticResource SmallFontSize}" Text="Filter" Style="{StaticResource Title}"  />
                            <ComboBox IsEditable="True" SelectedIndex="0" Text="{Binding SelectedExtension, UpdateSourceTrigger=PropertyChanged}" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center" Margin="{StaticResource DefaultLeftMargin}" Width="200">
                                <ComboBox.ItemsSource>
                                    <x:Array Type="{x:Type mscorlib:String}">
                                        <mscorlib:String>*.3gp|*.act|*.AIFF*.|*.aac*.|*.ALAC*.|*.amr*.|*.atrac*.|*.Au*.|*.awb*.|*.dct*.|*.dss*.|*.dvf*.|*.flac*.|*.gsm*.|*.iklax*.|*.IVS*.|*.m4a*.|*.m4p*.|*.mmf*.|*.mp3*.|*.mpc*.|*.msv*.|*.ogg*.|*.Opus*.|*.ra*.|*.raw*.|*.TTA*.|*.vox*.|*.wav*.|*.wma*.|*.wv</mscorlib:String>
                                        <mscorlib:String>*.*</mscorlib:String>
                                    </x:Array>
                                </ComboBox.ItemsSource>
                                <ComboBox.InputBindings>
                                    <KeyBinding Key="Enter" Command="{Binding RefreshFilelistCommand}" />
                                </ComboBox.InputBindings>
                            </ComboBox>
                        </StackPanel>
                    </StackPanel>
                </Expander>

                <ListView                      
                    FontSize="{StaticResource SmallFontSize}" 
                    ItemsSource="{Binding Files}"  
                    SelectionMode="Extended"    
                    VirtualizingStackPanel.IsVirtualizing="False"
                    helper:ListBoxMultipleSelectorHelper.SelectedItems="{Binding SelectedFiles, Mode=TwoWay}"            
                    >
                    <ListView.InputBindings>
                        <KeyBinding Key="Space" Command="{Binding CheckSelectedItemsCommand}" />
                    </ListView.InputBindings>
                    <ListView.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Check selected" Command="{Binding CheckSelectedItemsCommand}"></MenuItem>
                            <MenuItem Header="Check/Uncheck all" Command="{Binding CheckAllItemsCommand}"></MenuItem>
                        </ContextMenu>
                    </ListView.ContextMenu>
                    <ListView.View>
                        <GridView>                            
                            <GridViewColumn>
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>                                        
                                        <mui:ModernButton EllipseDiameter="18" Width="16" Height="16" IconData="{StaticResource playPathData}" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM.PlayFileCommand}"></mui:ModernButton>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding FileName, Converter={StaticResource filenameConverter}}" />
                        </GridView>
                    </ListView.View>

                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction CommandParameter="{Binding SelectedFiles}" Command="{Binding ShowFileTagCommand}" />
                            <i:InvokeCommandAction Command="{Binding PreviewPatternCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

                </ListView>
            </DockPanel>

            <StackPanel HorizontalAlignment="Center" Grid.Column="1" Grid.RowSpan="2" Margin="{StaticResource DefaultTopMargin}">
                <StackPanel.Style>
                    <Style TargetType="{x:Type StackPanel}">
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Files.Count}" Value="0">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Style>
                <TextBlock HorizontalAlignment="Center">List is empty</TextBlock>
                <TextBlock  HorizontalAlignment="Center" Margin="0, 5, 0, 0">
                    <Hyperlink Command="{Binding OpenFolderDialogCommand}">Click here</Hyperlink>
                </TextBlock>
            </StackPanel>-->
            
        </Grid>

    </DockPanel>

</UserControl>
